package org.example.java.socket.date;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * User: ZhangJuntao
 * Date: 14-2-11
 * Time: 上午10:45
 */
public class DateServer {
  /**
   * Runs the server.
   */
  public static void main(String[] args) throws IOException {
    ServerSocket listener = new ServerSocket(19090);
    try {
      while (true) {
        System.out.println("\nlistener.....");
        Socket socket = listener.accept();
        try {
          System.out.println("accept");
          PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
          TimeUnit.SECONDS.sleep(1);
          System.out.println("out print");
          out.println(System.getProperty("os.name") + " date:" + new Date().toString());
        } catch (InterruptedException e) {
          e.printStackTrace();
        } finally {
          socket.close();
        }
      }
    } finally {
      listener.close();
    }
  }
}
